<template>
  <div class="contentShadow">
    <el-upload
        action=""
        accept=".xlsx"
        :auto-upload="false"
        :before-upload="beforeUpload"
        :on-change="uploadFile"
        style="display: inline-block;"
    >
      <el-button size="small" type="primary">点击导入</el-button>
      <div slot="tip" class="el-upload__tip">请上传GPA表格</div>
    </el-upload>

  </div>
</template>

<script>

import {uploadGrade} from "@/api/upload";

export default {
  methods: {
    beforeUpload(file) {
      console.log(file);
    },
    uploadFile(file) {
      const formData = new FormData();
      formData.append('file', file.raw);

      // 发起上传请求
      uploadGrade(formData).then(response => {
        if (response.code === 200) {
          this.$message.success(response.msg)
        } else {
          this.$message.error(response.msg)
        }
      }).catch(error => {
        this.$message.error('文件上传失败')
        console.log(error)
      });
    }
  },
  data() {
    return {
      // selectedFile: null
    };
  }
};
</script>
